package com.sdry.web.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sdry.entity.PartOutOrder;
import com.sdry.entity.PartOutStore;
import com.sdry.service.PartOutOrderService;
import com.sdry.service.PartOutStoreService;
import com.sdry.utils.RequestResult;
import com.sdry.utils.TableResult;

/**
 * 
* @Title: PartOutOrderController.java
* @Package com.sdry.web.controller
* @Description: 出库
* @author cb
* @date 2018年7月31日
* @version V1.0
 */
@Controller
@RequestMapping("/partOutOrder")
public class PartOutOrderController {
	
	
	
	
	@Resource
    private PartOutOrderService partOutOrderService;
	
	
	@Resource
	private PartOutStoreService partOutStoreService;
	
	
	/**
	 * 跳转到list页面
	 * @return
	 */
	@RequestMapping("/PagePartOutOrder")
	public String PagePartOutOrder() {
		
		return "PartOutOrder/list";
	}
	
	/**
	 * 添加
	 * @param partOutOrder
	 * @return
	 */
	@RequestMapping("/insert")
	@ResponseBody
	public Map<String, Object> insert(PartOutOrder partOutOrder,@DateTimeFormat(pattern = "yyyy-MM-dd")Date time) {
		
		partOutOrder.setOdate(time);
		
		int effect = partOutOrderService.insertSelective(partOutOrder);
		
		return RequestResult.requestResultInt(effect);
		
	}
	
	/**
	 * 分页
	 * @param limit 大小
	 * @param offset 当前页
	 * @return
	 */
	@RequestMapping("/list")
	@ResponseBody
	public TableResult list(String conde,@RequestParam(value="limit",required=false)String limit,@RequestParam(value="offset",required=false)String offset) {
		
		
		
		PageHelper.startPage(Integer.parseInt(offset), Integer.parseInt(limit));
		
		Map<String, Object> map = new HashMap<>();
		
		map.put("conde", conde);
		
		List<PartOutOrder> list = partOutOrderService.selectAll(map);
    	
    	PageInfo<PartOutOrder> info = new PageInfo<PartOutOrder>(list);
    	
    	TableResult tableResult = new TableResult(info.getTotal(), info.getList()); 
    	
		return tableResult;
	}
	
	/**
	 * 删除
	 * @param ids 主键
	 * @return
	 */
	@RequestMapping("/delete")
	@ResponseBody
	public Map<String, Object> delete(String ids) {
		
		int effect = 0;
		
		String[] split = ids.split(",");
		
		for (String str : split) {
			
			effect = partOutOrderService.delete(Long.parseLong(str));
			
		}
		
		return RequestResult.requestResultInt(effect);
		
	}
	
	@RequestMapping("/listDetailed")
	@ResponseBody
	public TableResult listDetailed(String oremark) {
		
		List<PartOutStore> list = partOutStoreService.listDetailed(oremark);
		
		TableResult tableResult = new TableResult(null, list); 
    	
		return tableResult;
	}
	
}
